<?php

require './online-books-resources/inc/functions.php';
session_name('book_catalog');
session_set_cookie_params(0, '/', '', false, true);
session_start();
mb_internal_encoding('UTF-8');
$connection = mysqli_connect('localhost', 'root', '', 'books_online');
if (!$connection) {
    echo 'Няма връзка към базата данни';
    exit();
}
mysqli_set_charset($connection, 'utf8');

$page = '';
if (isset($_GET['p'])) {
    switch ($_GET['p']) {
        case 'index':
            $page = 'home';
            break;
        case 'book':
            $page = 'book';
            break;
        case 'new-book':
            $page = 'new-book';
            break;
        case 'author':
            $page = 'author';
            break;
        case 'new-author':
            $page = 'new-author';
            break;
        case 'user':
            $page = 'user';
            break;
        case 'login':
            $page = 'login';
            break;
        case 'logout':
            $page = 'logout';
            break;
        case 'register':
            $page = 'register';
            break;
        default:
            $page = 'home';
            break;
    }
} else {
    $page = 'home';
}

require './online-books-resources/business-logic/' . $page . '.php';